const { exec_shell } = require("../utils/shell_tool");
const { BaseCommand } = require("./base");
const { shareData } = require("./share_data");

class SvnAddCommand extends BaseCommand {
    async execute() {
        const data = this.selfData;
        const status = await exec_shell({
            cmd: "svn status",
            cwd: data.cwd,
            capture_stdout: true,
        });
        for (const line of shareData.processPipes(
            status,
            "splitlines|remove_empty",
        )) {
            if (line[0] !== "?") continue;
            const status_path = line.substring(8);
            await exec_shell({
                ...data,
                cmd: `svn add "${status_path}"`,
            });
        }
    }
}

module.exports = {
    SvnAddCommand,
};
